package libra.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import libra.model.JsonResult;
import libra.model.Provider_Pay;

@RestController
@RequestMapping("consumer")
public class ConsumerReqController {
	@Autowired
	RestTemplate restTemplate;
	
	@Value("${server.servlet.context-path}")
	String from;
	
	@RequestMapping("create")
	public Object create( HttpServletRequest req ){
		// 封装参数，千万不要替换为Map与HashMap，否则参数无法传递
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
        paramMap.add("serial", from + "_@_" + Provider_Pay.genUuid());
		return restTemplate.postForObject("http://127.0.0.1:20100/provider_payment_20100/provider/save", paramMap, JsonResult.class);
	}
	
	@RequestMapping("find")
	public Object find( Integer id, HttpServletRequest req ){
		// 封装参数，千万不要替换为Map与HashMap，否则参数无法传递
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
        paramMap.add("id", id);
		return restTemplate.postForObject("http://127.0.0.1:20100/provider_payment_20100/provider/queryOne", paramMap, JsonResult.class);
	}
	@RequestMapping("list")
	public Object list( HttpServletRequest req ){
		// 封装参数，千万不要替换为Map与HashMap，否则参数无法传递
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
		return restTemplate.postForObject("http://127.0.0.1:20100/provider_payment_20100/provider/queryList", paramMap, JsonResult.class);
	}
}
